package likou.tanxin;

import java.util.HashSet;
import java.util.Set;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2020/11/07 10:06
 */
public class _874 {
    public static void main(String[] args) {
        System.out.println(robotSim(new int[]{4,-1,4,-2,4},new int[][]{{2,4}}));
    }
    public static int robotSim(int[] commands, int[][] obstacles) {
        int[] dx = new int[]{0, 1, 0, -1};
        int[] dy = new int[]{1, 0, -1, 0};
        int x = 0, y = 0, direction = 0;
        Set<Integer> obstacleSet = new HashSet<>((int) (obstacles.length / 0.75) + 1);
        for (int[] o : obstacles) {
            int ox = o[0] + 30000;
            int oy = o[1] + 30000;
            obstacleSet.add((ox << 16) | oy);
        }
        int max = 0;
        for (int cmd : commands) {
            switch (cmd) {
                case -2:
                    direction = (direction + 3) % 4;
                    break;
                case -1:
                    direction = (direction + 1) % 4;
                    break;
                default:
                    for (int step = 0; step < cmd; step++) {
                        x += dx[direction];
                        y += dy[direction];
                        System.out.println((x+30000)<<16);
                        System.out.println(y + 30000);
                        int code = ((x + 30000) << 16) | (y + 30000);
                        if (obstacleSet.contains(code)) {
                            x -= dx[direction];
                            y -= dy[direction];
                            break;
                        }
                    }
                    max = Math.max(max, x * x + y * y);
                    break;
            }
        }
        return max;
    }
}
